﻿@model SMEsCustomer360Degree.Models.ViewModels.PortfolioManagement.DataAccountPlanningViewModel

<div class="">
    <div class="row">
        <div class="col-md-12">
            <div class="x_panel">
                <div class="x_content">
                    <div class="" role="tabpanel" data-example-id="togglable-tabs">
                        <ul class="nav nav-tabs bar_tabs sme-tabs" role="tablist">
                            <li id="pm-ap-tab" role="presentation" class="active">
                                @Html.ActionLink(@SMEsCustomer360Degree.Core.Resources.Resource.AccountPlanning, "AccountPlanning", "PortfolioManagement", null, null)
                            </li>
                            <li id="pm-pm-tab" role="presentation" class="">
                                @Html.ActionLink(@SMEsCustomer360Degree.Core.Resources.Resource.PortManagement, "PortfolioManagement", "PortfolioManagement", null, null)
                            </li>
                        </ul>
                        <div id="myTabContent" class="tab-content">
                            <div role="tabpanel" class="tab-pane fade active in" id="tab_content2" aria-labelledby="profile-tab">
                                <div class="row">
                                    <div class="col-md-12 col-sm-12 col-xs-12">
                                        <div class="x_panel">
                                            <div class="x_title">
                                                <h2>
                                                    @SMEsCustomer360Degree.Core.Resources.Resource.Edit
                                                    <small>
                                                        @SMEsCustomer360Degree.Core.Resources.Resource.AccountPlanning
                                                    </small>
                                                </h2>
                                                <ul class="nav navbar-right panel_toolbox">
                                                    <li>
                                                        <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                                    </li>
                                                </ul>
                                                <div class="clearfix"></div>
                                            </div>
                                            <div class="x_content">
                                                <ul class="nav nav-tabs bar_tabs sme-tabs" role="tablist">
                                                    <li id="pm-ap-data-tab" role="presentation" class="">
                                                        @Html.ActionLink(@SMEsCustomer360Degree.Core.Resources.Resource.AccountPlanningEdit, "EditAccountPlanning", "PortfolioManagement", new { cif = @Model.listDataAccountPlanning.FirstOrDefault().Cif }, null)
                                                    </li>
                                                    <li id="pm-ap-finance-tab" role="presentation" class="">
                                                        @Html.ActionLink(@SMEsCustomer360Degree.Core.Resources.Resource.AccountPlanningEditFinance, "EditAccountPlanningFinance", "PortfolioManagement", new { cif = @Model.listDataAccountPlanning.FirstOrDefault().Cif }, null)
                                                    </li>
                                                    <li id="pm-ap-product-holding-tab" role="presentation" class="active">
                                                        @Html.ActionLink(@SMEsCustomer360Degree.Core.Resources.Resource.AccountPlanningEditProductHolding, "EditProductHolding", "PortfolioManagement", new { cif = @Model.listDataAccountPlanning.FirstOrDefault().Cif }, null)
                                                    </li>
                                                </ul>
                                                <div id="cp_ap_edit_data"></div>
                                                <div class="form-group">
                                                    <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                                                        <a href="/PortfolioManagement/AccountPlanning" class="btn btn-primary" id="pm-ap-cancel-btn">Cancel</a>
                                                        <button class="btn btn-success" onclick="return submitData();" id="pm-ap-submit-btn">Submit</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


@section scripts
{
    <!--Table editable-->
    <script src="/scripts/tableeditable/editproductholding.js"></script>

    <script type="text/javascript">
        // Execute on page load
        $(document).ready(function () {
            var content = [["",@DateTime.Now.Year-1, @DateTime.Now.Year, "@SMEsCustomer360Degree.Core.Resources.Resource.Jan", "@SMEsCustomer360Degree.Core.Resources.Resource.Feb", "@SMEsCustomer360Degree.Core.Resources.Resource.Mar", "@SMEsCustomer360Degree.Core.Resources.Resource.Apr", "@SMEsCustomer360Degree.Core.Resources.Resource.May", "@SMEsCustomer360Degree.Core.Resources.Resource.Jun", "@SMEsCustomer360Degree.Core.Resources.Resource.Jul", "@SMEsCustomer360Degree.Core.Resources.Resource.Aug", "@SMEsCustomer360Degree.Core.Resources.Resource.Sep", "@SMEsCustomer360Degree.Core.Resources.Resource.Oct", "@SMEsCustomer360Degree.Core.Resources.Resource.Nov", "@SMEsCustomer360Degree.Core.Resources.Resource.Dec"]];
            var data =@Html.Raw(Json.Encode(Model.listDataAccountPlanning));
            for (var r = 0; r < data.length; r++) {
                var row = [];
                if (r==44) {
                    row.push(data[r]['GroupCri']);
                    row.push(data[r]['LastYear']);
                    row.push(data[r]['Year']);
                    row.push(data[r]['Month1']);
                    row.push(data[r]['Month2']);
                    row.push(data[r]['Month3']);
                    row.push(data[r]['Month4']);
                    row.push(data[r]['Month5']);
                    row.push(data[r]['Month6']);
                    row.push(data[r]['Month7']);
                    row.push(data[r]['Month8']);
                    row.push(data[r]['Month9']);
                    row.push(data[r]['Month10']);
                    row.push(data[r]['Month11']);
                    row.push(data[r]['Month12']);
                    row.push(data[r]['DataType']);
                    row.push(data[r]['GroupRow']);
                }else{
                    row.push(data[r]['GroupCri']);
                    row.push(data[r]['Name']);
                    row.push(data[r]['LastYear']);
                    row.push(data[r]['Year']);
                    row.push(data[r]['Month1']);
                    row.push(data[r]['Month2']);
                    row.push(data[r]['Month3']);
                    row.push(data[r]['Month4']);
                    row.push(data[r]['Month5']);
                    row.push(data[r]['Month6']);
                    row.push(data[r]['Month7']);
                    row.push(data[r]['Month8']);
                    row.push(data[r]['Month9']);
                    row.push(data[r]['Month10']);
                    row.push(data[r]['Month11']);
                    row.push(data[r]['Month12']);
                    row.push(data[r]['DataType']);
                    row.push(data[r]['GroupRow']);
                }

                content.push(row);
            }
            $('#cp_ap_edit_data').flextabledit({
                content: content,
                addTableClass: "table table-bordered table-striped jambo_table"
            });

        });
        function submitData() {
            var data = $('#cp_ap_edit_data').flextabledit('getData');
            var jsonData = JSON.stringify(data);
            var cif = getParameterByName('cif');
            $.ajax({
                url: '@Url.Action("EditProductHoldingAction", "PortfolioManagement")',
                type: "POST",
                data: { dataedit: jsonData, cif:cif },
                success: function (data_response) {
                    if (data_response==true) {
                        window.location.replace("@Url.Action("AccountPlanning", "PortfolioManagement")");
                    }
                }
            })
            return false;
        }
        function getParameterByName(name, url) {
            if (!url) url = window.location.href;
            name = name.replace(/[\[\]]/g, "\\$&");
            var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
                results = regex.exec(url);
            if (!results) return null;
            if (!results[2]) return '';
            return decodeURIComponent(results[2].replace(/\+/g, " "));
        }
    </script>;
    <script type="text/javascript">
        function startPageTourGuide() {
            var intro = introJs();
            var steps = [
                    {
                        element: '#pm-ap-tab',
                        intro: "@SMEsCustomer360Degree.Core.Resources.Resource.TourGuideAccountPlanningTab"
                    },
                    {
                        element: '#pm-pm-tab',
                        intro: "@SMEsCustomer360Degree.Core.Resources.Resource.TourGuidePortManTab",
                        position: 'right'
                    },
                    {
                        element: '#pm-ap-data-tab',
                        intro: '@SMEsCustomer360Degree.Core.Resources.Resource.TourGuideAccViewDataTab',
                        position: 'bottom'
                    },
                    {
                        element: '#pm-ap-finance-tab',
                        intro: '@SMEsCustomer360Degree.Core.Resources.Resource.TourGuideAccViewFinanceTab',
                        position: 'right',
                    },
                    {
                        element: '#pm-ap-product-holding-tab',
                        intro: "@SMEsCustomer360Degree.Core.Resources.Resource.TourGuideAccViewProductHoldingTab",
                        position: 'bottom'
                    },
                    {
                        element: "#pm-ap-edit-product-holding-table",
                        intro: "@SMEsCustomer360Degree.Core.Resources.Resource.TourGuideEditFinanceTable",
                        position: 'bottom'
                    },
                    {
                        element: '#edit-table-from',
                        intro: "@SMEsCustomer360Degree.Core.Resources.Resource.TourGuideEditFinanceAvailCol",
                        position: 'bottom'
                    },
                    {
                        element: '#pm-ap-cancel-btn',
                        intro: "@SMEsCustomer360Degree.Core.Resources.Resource.TourGuideEditCancelBtn",
                        position: 'bottom'
                    },
                    {
                        element: '#pm-ap-submit-btn',
                        intro: "@SMEsCustomer360Degree.Core.Resources.Resource.TourGuideEditSubmitBtn",
                        position: 'bottom'
                    }
            ];
            intro.setOptions({
                steps: steps,
                showProgress: true,
                scrollToElement: true,
            });
            intro.setOption('tooltipPosition', 'auto');
            intro.setOption('positionPrecedence', ['left', 'right', 'bottom', 'top'])
            intro.start();
        }
    </script>
}